# -*- coding: utf-8 -*-
import scrapy
from urllib import request
from PIL import Image

class ZhycspiderSpider(scrapy.Spider):
    name = 'zhycSpider'
    allowed_domains = ['chinahr.com']
    start_urls = ['http://passport.chinahr.com/pc/tologin?backUrl=http://www.chinahr.com/jobs/']

    def parse(self, response):
        captcha_url = response.css("img#comPicValidateCode::attr(src)").get()
        if not captcha_url:
            self.regonize_captcha(captcha_url)
            captcha_id = response.xpath("//input[@class='com_img']@value").get()


    # 处理验证码
    def regonize_captcha(self,captcha_url):
        # 保存图片
        request.urlretrieve(captcha_url, 'captcha.png')
        # 打开图片
        image = Image.open('captcha.png')
        image.show()
        captcha = input("请输入验证码：")
        return captcha
